package com.ohuang.exceptionhandler;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.Application;
import android.widget.Toast;

import com.ohuang.crash.CrashUtil;


public class MyApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
//        if (isMainProcess()) {
//            CrashHandler.getInstance().setRunnable(new Runnable() {
//                @Override
//                public void run() {
//
//                }
//            });
//            CrashHandler.getInstance().setHandleExceptionReturn(true);
//            CrashHandler.getInstance().disableLauncher(false);
//        }

//        CrashUtil.getInstance().init(this);
    }

    /**
     * 判断是否为主进程
     */
    @SuppressLint("ServiceCast")
    private boolean isMainProcess(){
        int pid = android.os.Process.myPid();
        android.app.ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                return getApplicationInfo().packageName.equals(appProcess.processName);
            }
        }
        return false;
    }
}
